﻿using System;
using System.Configuration;
using System.Data;

namespace LMD.Lib.Oracle
{
    public static class DBUtils
    {
        public static bool IsQueryValid(String sxQuery)
        {
            DBLib dbl = new DBLib();
            dbl.BeginTransaction();

            bool bValid = false;
            try
            {
                dbl.GetDataTable(sxQuery);
                bValid = true;
            }
            catch(Exception ex)
            {
                ex.ToString();
            }
            finally
            {
                dbl.EndTransaction(false);
            }

            return bValid;
        }

        public static bool IsQueryValid(String sxQuery, String sxConnectionName, ref DataTable dt)
        {
            String sxConnString = Connection.ICP;

            try
            {
                sxConnString = ConfigurationManager.ConnectionStrings[sxConnectionName].ConnectionString;
            }
            catch { }

            DBLib dbl = new DBLib(sxConnString);
            dbl.BeginTransaction();

            bool bValid = false;
            try
            {
                dt = dbl.GetDataTable(sxQuery);
                bValid = true;
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
            finally
            {
                dbl.EndTransaction(false);
            }

            return bValid;
        }
    }
}
